﻿#include "testKeyboard.h"
#include "ui_testKeyboard.h"

#include <QDebug>
#include <QMouseEvent>

/* 测试类 */
#include "virtualkeyboard.h"

testKeyboard::testKeyboard(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::testKeyboard)
{
    ui->setupUi(this);

#ifdef  DEBUG_MODE
    qDebug() << __func__ << __LINE__ << "---------------------testKeyboard start----------------------" << endl;
#endif

    QObjectList cs = this->children();  // children()返回的是所有子节点,此时返回的是widget下的控件

    for (int i = 0; i < cs.size(); i++)
    {
        g_objVec.push_back(cs[i]);
        //qDebug() << g_objVec[i]->objectName();
    }

    for (int i = 0; i < cs.size();i++)
    {
        g_objVec[i]->installEventFilter(this);   // 为所有控件安装事件过滤器
    }

    g_doubleSpinBox = this->findChildren<QDoubleSpinBox *>(); // 寻找ui中的QDoubleSpinBox这一类的控件
    g_spinBox = this->findChildren<QSpinBox *>();             // 寻找ui中的QSpinBox这一类的控件

    this->show();

#ifdef  DEBUG_MODE
    qDebug() << __func__ << __LINE__ << "---------------------testKeyboard end----------------------" << endl;
#endif
}

testKeyboard::~testKeyboard()
{
    delete ui;
}

bool testKeyboard::eventFilter(QObject *watched, QEvent *event)
{
    // 鼠标按下事件
    if(event->type() == QEvent::MouseButtonPress){
        QMouseEvent* mouseEvent = static_cast<QMouseEvent*>(event);
        if(mouseEvent->button() == Qt::LeftButton){
            emit widget_clicked(nullptr);
        }
    }
    return QWidget::eventFilter(watched, event);
}
